import com.sun.script.javascript.RhinoScriptEngine;

import java.util.Scanner;
import java.util.StringTokenizer;

class Point {
public Point(){
	System.out.print("Enter x coordinate");
	boolean op;
	Scanner sc = new Scanner(System.in);
	do {
	op = false;
		if(sc.hasNextDouble()){
			x = sc.nextDouble();
		}else{
			System.out.print("You enter not a number");
			op = true;
		}		
	}while (op);
	
	System.out.print("Enter y coordinate");
	do {
	op = false;
		if(sc.hasNextDouble()){
			y = sc.nextDouble();
		}else{
			System.out.print("You enter not a number");
			op = true;
		}		
	}while (op);
}
public Point(double a, double b){
	x = a;
	y = b;
}
public double lenght(Point p1,Point p2){
	double l;
	l=Math.sqrt(Math.pow(p1.x - p2.x, 2)+Math.pow(p1.y - p2.y,2));
	return l;
}
public static boolean inLine(Point p1, Point p2, Point p3){
	boolean in;
	in = (p1.x - p2.x)/(p3.x - p2.x) == (p1.y - p2.y)/(p3.y - p2.y);
	return in;
}
public void vectPlus(Point a){
	this.x += a.x;
	this.y += a.y;
}
public void vectMinus(Point a){
	this.x -= a.x;
	this.y -= a.y;
}
public void toPolar(){
	double r, fi;
	fi = 0;
	r = Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
	if(this.x > 0 && this.y >= 0){
		fi = Math.atan(this.y/this.x);
		}else{
	if(this.x > 0 && this.y < 0){
		fi = Math.atan(this.y/this.x) + 2*Math.PI;
		}else{
	if(this.x<0){
		fi = Math.atan(this.y/this.x) + Math.PI;
		}else{
	if(this.x == 0 && this.y > 0){
		fi = Math.PI/2;
		}else{
	if(this.x == 0 && this.y < 0){
		fi = 3*Math.PI/2;
		}else{
	if(this.x == 0 && this.y == 0){
		fi = 0;
		}
		}
		}
		}
		}
	}
	x = r;
	y = fi;
}
public void toDecart(){
	double r;
	r = Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
	this.x = r*Math.cos(this.y);
	this.y = r*Math.sin(this.y);
}
public void addAngle(double alpha){
	this.y += alpha;
}
    @Override
public String toString(){
    String st = "point with coords x ="+this.x + ", y =" + this.y;
        return st;
}
public void vectorMultipl(double mu){
    this.x *= mu;
    this.y *= mu;
   }
public static Point medianCross(Point a, Point b, Point c){
    Point med = new Point(0,0);
    med.x = (a.x + b.x + c.x) / 3;
    med.y = (a.y + b.y + c.y) / 3;
    return med;
}
	private double x;
	private double y;
}
class Triangle{
public Triangle(){
	boolean li;
	do{		
		li = false;
		System.out.println("Enter a coords");
		 a = new Point();
		System.out.println("Enter b coords");
		 b = new Point();
		System.out.println("Enter c coords");
		 c = new Point();
			if(Point.inLine(a,b,c)){
				li = true;
				System.out.println("All points are in line");
			}
	} while(li);
}
        @Override
public String toString(){
    String st = "triangle with tops at " + this.a + " " + this.b + " " + this.c;
    return st;
}
public void rotateTriangle(double deg){
	Point m = Point.medianCross(this.a, this.b, this.c) ;
    System.out.println("mass centre :"+ m);
	a.vectMinus(m);
	b.vectMinus(m);
	c.vectMinus(m);
    System.out.println(" " + a + b + c);
	a.toPolar();
	b.toPolar();
	c.toPolar();
    System.out.println(" " + a + b + c);
	a.addAngle(deg);
	b.addAngle(deg);
	c.addAngle(deg);
	a.toDecart();
	b.toDecart();
	c.toDecart();
	a.vectPlus(m);
	b.vectPlus(m);
	c.vectPlus(m);
}
private Point a;
private Point b;
private Point c;
}

public class tri {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Triangle tr = new Triangle()  ;


        tr.rotateTriangle(30);
        System.out.println("Rotated " + tr);

	}

}
